<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\View;
use app\api\logic\Indexs;
class Index extends Controller
{
    public function __construct(Request $request){
        parent::__construct($request);
        if(session('userid')==''){
            $name='';
        }else{
            $name=Db::name('user')->where(['userid'=>session('userid')])->value('nickname');
        }
        $this->assign('name',$name);
        $this->assign('title','铭家');
    }
    
    /**
    * 跳转到首页
    */
    public function index(Request $request)
    {  
        $this->assign('title','首页');
        return view('index');
    }
    /**
    * 个人中心
    */
    public function userlist()
    {
        if(session('userid')==''){
            jsBack('请前去登陆','/api/register');
            return false;
        }
        $page=DB::name('zhuanji')->where(['userid'=>session('userid')])->paginate(8,false,['type' => 'bootstrap','var_page' => 'page',]);
        $user=DB::name('user')->where(['userid'=>session('userid')])->find();
        $photo=$page->all();
        // dump($photo);die;
        $this->assign('user',$user);
        $this->assign('photo',$photo);
        $this->assign('page',$page);
        $this->assign('title','个人中心');
        return view('userlist');
    }
    public function userAjax()
    {
        $page=Db::name('photos')->where(['userid'=>session('userid')])->paginate(8,false,['type' => 'bootstrap','var_page' => 'page',]);
        $photos=$page->all();
        $photoslist['page']=$page;
        $photoslist['list']=$photos;
        if($photos){
            res('success','成功',$photoslist);
        }else{
            res('error','失败');
        }
        
    }
    public function userAjax2()
    {
        $page=Db::name('zhuanji')->where(['userid'=>session('userid')])->paginate(8,false,['type' => 'bootstrap','var_page' => 'page',]);
        $zhuanji=$page->all();
        $zhuanjilist['page']=$page;
        $zhuanjilist['list']=$zhuanji;
        if($zhuanji){
            res('success','成功',$zhuanjilist);
        }else{
            res('error','失败');
        }
    }
    /**
    * 站内信
    */
    public function mail(){
        return view('mail');
    } 
}